package eu.epfc.dnet.mastermind.model.utils;

import eu.epfc.dnet.mastermind.model.pojos.TokenColorList;
import eu.epfc.dnet.mastermind.model.beans.Token;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 *
 * @author Pierre Buvé & Nicolas Van Damme
 */
public class RandomSolutionGenerator {
    
    private List<Token> tokenList;
    private List<Token> solutionList;
    
    public RandomSolutionGenerator() {
        
    }
    
    /**
     * Retourne une nouvelle solution aléatoire.
     * @return 
     */
    public List<Token> getNewSolution() {
        generateSolution(); 
        return solutionList;
    }
    
    /**
     * Methode chargée de générer une solution.
     */
    private void generateSolution() {
        TokenColorList tokenColorList = new TokenColorList();
        tokenList = tokenColorList.getListColor();
        solutionList = new ArrayList<Token>();
        
        String value;
        List<String> listTempNumb = new ArrayList<String>(); 
        Random r = new Random();
        while (listTempNumb.size() <4) {
            value = (r.nextInt(8))+"";
            if (!(listTempNumb.contains(value))) {
                listTempNumb.add(value);
            } 
        }
        for (int i=0 ; i<listTempNumb.size(); i++) {
            solutionList.add(tokenList.get(Integer.parseInt(listTempNumb.get(i))));
        }
        System.out.println(this.getClass() + " : " + "Solution générée " + solutionList.toString());
        

    }
}